/**
 * Sample React Native App By Wyh
 * Created by wyh on 15/12/23.
 */
'use strict';

import {
  AsyncStorage
} from 'react-native';

import {
  Store,
  msg,
} from 'iflux-native';


/**
 * 数据中心
 */
var appStore = module.exports = Store({
  username: '',
  password: '',
  isHide: false //密码隐藏按钮标记
});


msg
  .on('login:pwdBtnChange', pwdBtnChange)
  .on('login:passwordChange', passwordChange)
  .on('login:usernameChange', usernameChange)
  .on('login:login', login);


/**
 * 用户名输入改变
 * @param username
 */
function usernameChange(username) {
  appStore.cursor().set('username', username);
}


/**
 * 密码输入改变
 * @param password
 */
function passwordChange(password) {
  appStore.cursor().set('password', password);
}


/**
 * 密码是否显示
 */
function pwdBtnChange() {
  appStore.cursor().set('isHide', !appStore.data().get('isHide'));
}


/**
 * 登录
 */
function login() {
  msg.emit('route:replaceRoute', {sceneName: 'Home'});
}
